// ----------------------------------
// RSDK Project: Sonic 1/Sonic 2
// Script Description: HUD Object
// Script Author: Christian Whitehead/Simon Thomley
// Unpacked by Rubberduckycooly's script unpacker
// ----------------------------------

//-------Aliases-------//
private alias 5 : TYPE_HUD

// Function declarations
reserve function HUD_DrawPC
reserve function HUD_DrawMobile

private alias saveRAM[494] : saved.bossGameMode //7B8 SData.bin
private alias saveRAM[495] : saved.bossType //7BC SData.bin
private alias saveRAM[496] : saved.BossMusic //7C0 SData.bin
private alias saveRAM[497] : saved.Character //7C4 SData.bin
private alias saveRAM[498] : saved.TimeLimit //7C8 SData.bin
private alias saveRAM[499] : saved.superMode //7CC SData.bin

// Static Values

// Tables

function HUD_DrawPC
	DrawSpriteScreenXY(10, 17, 13)
	if stage.activeList != BONUS_STAGE
		if stage.minutes == 9
			if object.value1 > 7
				DrawSpriteScreenXY(11, 17, 29)
			end if
		end if
	else
		if stage.minutes == 14
			if object.value1 > 7
				if saved.TimeLimit == 1
					DrawSpriteScreenXY(11, 17, 29)
				endif
			end if
		end if
	end if
	if object[0].value0 == 0
		if object.value1 > 7
			DrawSpriteScreenXY(12, 17, 45)
		end if
	end if
	DrawNumbers(0, 104, 13, player.score, 6, 8, 0)
	if options.gameMode < 2
		if options.bossGame == 1
			DrawSpriteScreenXY(13, 67, 29)
			DrawNumbers(0, 104, 29, stage.milliSeconds, 2, 8, 1)
		else
			DrawSpriteScreenXY(14, 67, 29)
		endif
	else
		DrawSpriteScreenXY(13, 67, 29)
		DrawNumbers(0, 104, 29, stage.milliSeconds, 2, 8, 1)
	end if
	DrawNumbers(0, 80, 29, stage.seconds, 2, 8, 1)
	DrawNumbers(0, 56, 29, stage.minutes, 2, 8, 0)
	DrawNumbers(0, 80, 45, object[0].value0, 3, 8, 0)
	if stage.debugMode == 1
		temp0 = object[0].xpos
		temp0 >>= 16
		Abs(temp0)
		temp1 = screen.xsize
		temp1 -= 24
		DrawNumbers(0, temp1, 13, temp0, 5, 8, 1)
		temp0 = object[0].ypos
		temp0 >>= 16
		Abs(temp0)
		DrawNumbers(0, temp1, 29, temp0, 5, 8, 1)
		temp1 -= 42
		if object[0].xpos >= 0
			DrawSpriteScreenXY(18, temp1, 15)
		else
			DrawSpriteScreenXY(36, temp1, 15)
		end if
		if object[0].ypos >= 0
			DrawSpriteScreenXY(19, temp1, 31)
		else
			DrawSpriteScreenXY(37, temp1, 31)
		end if
	end if
	temp0 = stage.playerListPos
	temp0 += 15
	DrawSpriteScreenXY(temp0, 16, 212)
	temp0 += 6
	DrawSpriteScreenXY(temp0, 33, 213)
	DrawSpriteScreenXY(20, 38, 222)
	if options.bossGame == 1
		DrawSpriteScreenXY(38, 48, 222)
	else
		DrawNumbers(24, 56, 218, player.lives, 2, 8, 0)
	endif
end function


function HUD_DrawMobile
	DrawSpriteScreenXY(10, 17, 9)
	if stage.activeList != BONUS_STAGE
		if stage.minutes == 9
			if object.value1 > 7
				DrawSpriteScreenXY(11, 17, 25)
			end if
		end if
	else
		if stage.minutes == 14
			if object.value1 > 7
				if saved.TimeLimit == 1
					DrawSpriteScreenXY(11, 17, 25)
				endif
			end if
		end if
	end if
	if object[0].value0 == 0
		if object.value1 > 7
			DrawSpriteScreenXY(12, 17, 41)
		end if
	end if
	DrawNumbers(0, 104, 9, player.score, 6, 8, 0)
	if options.gameMode < 2
		DrawSpriteScreenXY(14, 67, 25)
	else
		DrawSpriteScreenXY(13, 67, 25)
		DrawNumbers(0, 104, 25, stage.milliSeconds, 2, 8, 1)
	end if
	DrawNumbers(0, 80, 25, stage.seconds, 2, 8, 1)
	DrawNumbers(0, 56, 25, stage.minutes, 1, 8, 1)
	DrawNumbers(0, 80, 41, object[0].value0, 3, 8, 0)
	if object[0].type == TypeName[Debug Mode]
		temp0 = object[0].xpos
		temp0 >>= 16
		Abs(temp0)
		temp1 = screen.xsize
		temp1 -= 16
		DrawNumbers(0, temp1, 25, temp0, 5, 8, 1)
		temp0 = object[0].ypos
		temp0 >>= 16
		Abs(temp0)
		DrawNumbers(0, temp1, 41, temp0, 5, 8, 1)
		temp1 -= 42
		if object[0].xpos >= 0
			DrawSpriteScreenXY(18, temp1, 27)
		else
			DrawSpriteScreenXY(36, temp1, 27)
		end if
		if object[0].ypos >= 0
			DrawSpriteScreenXY(19, temp1, 43)
		else
			DrawSpriteScreenXY(37, temp1, 43)
		end if
		DrawSpriteScreenXY(34, screen.xcenter, 16)
		DrawSpriteScreenXY(35, screen.xcenter, 16)
	end if
	temp1 = screen.xsize
	temp1 -= 64
	temp0 = stage.playerListPos
	temp0 += 15
	DrawSpriteScreenXY(temp0, temp1, 8)
	temp1 += 17
	temp0 += 6
	DrawSpriteScreenXY(temp0, temp1, 9)
	temp1 += 5
	DrawSpriteScreenXY(20, temp1, 18)
	temp1 += 18
	DrawNumbers(24, temp1, 16, player.lives, 2, 8, 0)
end function


event ObjectDraw
	if object[0].value0 == 0
		object.value1++
		if object.value1 == 16
			object.value1 = 0
		end if
	else
		if stage.activeList != BONUS_STAGE
			if stage.minutes == 9
				object.value1++
				if object.value1 == 16
					object.value1 = 0
				end if
			end if
		else
			if stage.minutes == 14
				object.value1++
				if object.value1 == 16
					object.value1 = 0
				end if
			end if
		end if
	end if
	CallFunction(object.value0)
end event


event ObjectStartup
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(0, 0, 8, 11, 1, 50)
	SpriteFrame(0, 0, 8, 11, 10, 50)
	SpriteFrame(0, 0, 8, 11, 19, 50)
	SpriteFrame(0, 0, 8, 11, 28, 50)
	SpriteFrame(0, 0, 8, 11, 1, 62)
	SpriteFrame(0, 0, 8, 11, 10, 62)
	SpriteFrame(0, 0, 8, 11, 19, 62)
	SpriteFrame(0, 0, 8, 11, 28, 62)
	SpriteFrame(0, 0, 8, 11, 1, 74)
	SpriteFrame(0, 0, 8, 11, 10, 74)
	SpriteFrame(0, 0, 40, 43, 1, 1)
	SpriteFrame(0, 0, 31, 11, 1, 119)
	SpriteFrame(0, 0, 39, 11, 1, 131)
	SpriteFrame(0, 0, 29, 4, 1, 45)
	SpriteFrame(0, 0, 3, 11, 37, 50)
	SpriteFrame(0, 0, 16, 16, 83, 18)
	SpriteFrame(0, 0, 16, 16, 100, 18)
	SpriteFrame(0, 0, 16, 16, 117, 18)
	SpriteFrame(0, 0, 8, 8, 1, 98)
	SpriteFrame(0, 0, 8, 8, 10, 98)
	SpriteFrame(0, 0, 6, 6, 19, 98)
	SpriteFrame(0, 0, 31, 7, 185, 18)
	if options.region == 0
		SpriteFrame(0, 0, 31, 7, 217, 18)
	else
		SpriteFrame(0, 0, 31, 7, 185, 26)
	end if
	SpriteFrame(0, 0, 31, 7, 217, 26)
	SpriteFrame(0, 0, 8, 8, 37, 64)
	SpriteFrame(0, 0, 8, 8, 46, 64)
	SpriteFrame(0, 0, 8, 8, 55, 64)
	SpriteFrame(0, 0, 8, 8, 64, 64)
	SpriteFrame(0, 0, 8, 8, 73, 64)
	SpriteFrame(0, 0, 8, 8, 82, 64)
	SpriteFrame(0, 0, 8, 8, 91, 64)
	SpriteFrame(0, 0, 8, 8, 100, 64)
	SpriteFrame(0, 0, 8, 8, 109, 64)
	SpriteFrame(0, 0, 8, 8, 118, 64)
	SpriteFrame(-16, 0, 8, 8, 127, 64)
	SpriteFrame(8, 0, 8, 8, 136, 64)
	SpriteFrame(0, 0, 8, 8, 25, 98)
	SpriteFrame(0, 0, 8, 8, 34, 98)
	SpriteFrame(0, 0, 11, 8, 120, 47)
	foreach (TypeName[HUD], arrayPos0, ALL_ENTITIES)
		if engine.deviceType == RETRO_STANDARD
			object[arrayPos0].value0 = HUD_DrawPC
		else
			object[arrayPos0].value0 = HUD_DrawMobile
		end if
	next
end event

event RSDKDraw
	DrawSprite(0)
end event

event RSDKLoad
	LoadSpriteSheet("Global/Display.gif")
	SpriteFrame(-16, -16, 32, 32, 1, 143)
end event
